package com.liull.papersystem.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * @Descriotion:
 * @Author longlong.liu
 * @Version 1.0
 * @Date 2021/10/27 13:58
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (Objects.isNull(request.getSession().getAttribute("userInfo"))) {
            response.sendRedirect(request.getContextPath() + "login");
            return false;
        } else {
            return true;
        }
    }
}